package com.xmut.mall.coupon.controller;

import com.xmut.mall.coupon.annotation.CheckJwt;
import com.xmut.mall.coupon.entity.FullDiscountEntity;
import com.xmut.mall.coupon.searchparams.ManagerFullDiscountSearchParam;
import com.xmut.mall.coupon.searchparams.SellerFullDiscountSearchParam;
import com.xmut.mall.coupon.service.FullDiscountService;
import com.xmut.mall.coupon.utils.RespBean;
import com.xmut.mall.coupon.vo.AddFullDiscountVo;
import com.xmut.mall.coupon.vo.PageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("coupon/fulldiscount")
public class FullDiscountController {
    @Autowired
    private FullDiscountService fullDiscountService;

    /**
     * 获取购物车结算时可用的满减活动
     * @param skuIds
     * @return
     */
    @PostMapping("/getCartCheckFullDiscount")
    public RespBean getCartCheckFullDiscount(@RequestBody List<Long> skuIds){
        List<FullDiscountEntity> list = fullDiscountService.getCartCheckFullDiscount(skuIds);
        return RespBean.success("获取成功",list);
    }

    /**
     * 获取商品详情里的满减优惠的信息
     * @param skuId
     * @return
     */
    @GetMapping("/getProductDetailFullDiscount/{skuId}")
    public RespBean getProductDetailFullDiscount(@PathVariable Long skuId){
        return fullDiscountService.getProductDetailFullDiscount(skuId);
    }

    /**
     * 获取商城官方后台的满减活动的详情
     * @param id
     * @return
     */
    @CheckJwt
    @GetMapping("/getManagerFullDiscountDetail/{id}")
    public RespBean getManagerFullDiscountDetail(@PathVariable Long id){
        return fullDiscountService.getManagerFullDiscountDetail(id);
    }

    /**
     * 获取商城管理端的满减活动分页数据
     * @param param
     * @return
     */
    @CheckJwt
    @PostMapping("/getManagerFullDiscountPage")
    public RespBean getManagerFullDiscountPage(@RequestBody ManagerFullDiscountSearchParam param){
        PageVO vo = new PageVO();
        BeanUtils.copyProperties(param,vo);
        return fullDiscountService.getManagerFullDiscountPage(vo,param);
    }

    /**
     * 删除满减活动
     * @param id
     * @return
     */
    @CheckJwt
    @DeleteMapping("/deleteFullDiscount/{id}")
    public RespBean deleteFullDiscount(@PathVariable Long id){
        return fullDiscountService.deleteFullDiscount(id);
    }

    /**
     * 重新开启活动
     * @param params
     * @return
     */
    @CheckJwt
    @PutMapping("/openFullDiscount")
    public RespBean openFullDiscount(@RequestBody Map<String,Object> params){
        return fullDiscountService.openFullDiscount(params);
    }

    /**
     * 关闭当前的满减活动
     * @param id
     * @return
     */
    @CheckJwt
    @PutMapping("/closeFullDiscount/{id}")
    public RespBean closeFullDiscount(@PathVariable Long id){
        return fullDiscountService.closeFullDiscount(id);
    }

    /**
     * 修改满减活动
     * @param vo
     * @return
     */
    @CheckJwt
    @PostMapping("/editFullDiscount")
    public RespBean editFullDiscount(@RequestBody AddFullDiscountVo vo){
        return fullDiscountService.editFullDiscount(vo);
    }

    /**
     * 根据传入的ID获取满减活动的详情
     * @param id
     * @return
     */
    @CheckJwt
    @GetMapping("/getFullDiscountDetail/{id}")
    public RespBean getFullDiscountDetail(@PathVariable Long id){
        return fullDiscountService.getFullDiscountDetail(id);
    }

    /**
     * 添加满减活动
     * @param vo
     * @return
     */
    @CheckJwt
    @PostMapping("/addFullDiscount")
    public RespBean addFullDiscount(@RequestBody AddFullDiscountVo vo){
        return fullDiscountService.addFullDiscount(vo);
    }

    /**
     * 获取卖家端的满减分页数据
     * @param param
     * @return
     */
    @CheckJwt
    @PostMapping("/getSellerFullDiscountPage")
    public RespBean getSellerFullDiscountPage(@RequestBody SellerFullDiscountSearchParam param){
        PageVO vo = new PageVO();
        BeanUtils.copyProperties(param,vo);
        return fullDiscountService.getSellerFullDiscountPage(vo,param);
    }

}
